package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.form.BasePageQuery;
import com.example.teachingSystem.pojo.form.semester.AddSemesterForm;
import com.example.teachingSystem.pojo.form.semester.UpdateSemesterForm;
import com.example.teachingSystem.pojo.vo.OptionVo;
import com.example.teachingSystem.pojo.vo.SemesterVo;
import com.example.teachingSystem.service.SemesterService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/semester")
@Tag(name = "学期模块")
public class SemesterController {

    @Autowired
    private SemesterService semesterService;

    @PostMapping("/one")
    @Operation(summary = "添加学期", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addSemester(@RequestBody @Validated AddSemesterForm addSemesterForm) {
        return semesterService.addSemester(addSemesterForm);
    }

    @PutMapping("/one")
    @Operation(summary = "修改学期", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateUserSign(@RequestBody @Validated UpdateSemesterForm updateSemesterForm) {
        return semesterService.updateSemester(updateSemesterForm);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "根据id删除学期", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteSemesterById(@PathVariable Long id) {
        return semesterService.deleteSemesterById(id);
    }

    @GetMapping("/more")
    @Operation(summary = "获取学期分页", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<SemesterVo> deleteSemesterById(BasePageQuery basePageQuery) {
        return semesterService.getSemester(basePageQuery);
    }

    @GetMapping("/option")
    @Operation(summary = "获取学期选项", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<OptionVo>>  getSemesterOptions() {
        return semesterService.getSemesterOptions();
    }
}